﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Windows.Forms;

namespace University.Workshop.Business
{
    public static class LogOnManager
    {
        public static bool LogOn(string userName, string password)
        {
            
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("All inputs required");
            }
            LogOnUser user = new LogOnUser();
            user.Dispose();
            if (Regex.IsMatch(userName,@"[^a-zA-Z]$"))
            {
                throw new ArgumentException("Username must have just letters");
            }
            if (user.ValidOperator(userName, password))
            {
                //MessageBox.Show("Entro");
                TripelDesDataAccess dal = new TripelDesDataAccess();
                dal.Dispose();
                TripleDESUtil DES = dal.Obtener(userName);
                TripleDesManager des_Manager = new TripleDesManager();
                String pass = des_Manager.DesEncriptar(DES.Encriptado, DES);
                //MessageBox.Show(pass);
                return (pass == password);
            }
            else
                return false;       

        }
        public static bool ExistOperator()
        {
            LogOnUser user = new LogOnUser();
            user.Dispose();
            if (user.ThereOperator())
                return true;
            else
                return false; 
        }
    }
}
